
//
//  XYCallDetailHeaderView.m
//  Zhihuijinfu
//
//  Created by XY Lv on 17/3/27.
//  Copyright © 2017年 王笛. All rights reserved.
//

#import "XYCallDetailHeaderView.h"
#import "XYCommon.h"
#import "XYSubviewsStyle.h"
@implementation XYCallDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self xyInitSubviews];
        [self xyInitFirstSubvies];
    }
    return self;
}

- (void)xyInitSubviews{
    _xyTitleLabel = [[UILabel alloc]init];
    [self addSubview:_xyTitleLabel];
    _xyTitleLabel.text = @"回访内容";
    
    _xyContentLabel = [[UILabel alloc]init];
    [self addSubview:_xyContentLabel];
    _xyContentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    _xyContentLabel.numberOfLines = 0;
    _xyContentLabel.textColor = xyCallContentColor;
    _xyContentLabel.font = [UIFont systemFontOfSize:13];
    _xyMsgImgView = [[UIImageView alloc]init];
    [self addSubview:_xyMsgImgView];
    [_xyMsgImgView setImage:[UIImage imageNamed:@"xy_icon_comment"]];
    
    _xyAlertLabel = [[UILabel alloc]init];
    [self addSubview:_xyAlertLabel];
    _xyAlertLabel.text = @"目前还没有人评论";
    _xyAlertLabel.textAlignment = NSTextAlignmentCenter;
    _xyAlertLabel.textColor = [UIColor lightGrayColor];
}

- (void)xyInitFirstSubvies{
    _xyFirstBgView = [[UIView alloc]init];
    [self addSubview:_xyFirstBgView];
    
    _xyAvatar = [[UIImageView alloc]init];
    [_xyFirstBgView addSubview:_xyAvatar];
    
    _userNameLabel = [[UILabel alloc]init];
    [_xyFirstBgView addSubview:_userNameLabel];
    _userNameLabel.font = xyUserNameTextFont;
    _userNameLabel.textColor = xyUserNameTextColor;
    
    _publishTimeLabel = [[UILabel alloc]init];
    [_xyFirstBgView addSubview:_publishTimeLabel];
    _publishTimeLabel.font =  xyPublisTimeFont;
    _publishTimeLabel.textColor = xyPublisTimeTextColor;
}

- (void)xySetSubviewsFrame{
    if([_xyDetailItem.type isEqualToString:@"2"]){
        [self xySetFirstSubviewsFrame];
        [self xySetBlowSubviewsFrameWithY:CGRectGetMaxY(_xyFirstBgView.frame) withOriginX:_xyAvatar.frame.origin.x];


    }else{
        CGFloat xyTitleLabelX  = xyPadding;
        CGFloat xyTitleLabelY  = xyPadding;
        CGFloat xyTitleLabelW  = xy(60);;
        CGFloat xyTitleLabelH  = xy(25);
        
        _xyTitleLabel.frame = CGRectMake(xyTitleLabelX, xyTitleLabelY, xyTitleLabelW, xyTitleLabelH);
        [self xySetBlowSubviewsFrameWithY:CGRectGetMaxY(_xyTitleLabel.frame) withOriginX:xyTitleLabelX];

    }
    
    
   
    

}

- (void)xySetFirstSubviewsFrame{
    
    _xyFirstBgView.frame = CGRectMake(0,xyPadding, WDScreenW, xyHeadImgViewH);
    
    
    CGFloat headImgViewX = xyPadding;
    CGFloat headImgViewY = xyPadding;
    CGFloat headImgViewW = xyHeadImgViewH;
    CGFloat headImgViewH = headImgViewW;
    _xyAvatar.frame = CGRectMake(headImgViewX, headImgViewY, headImgViewW, headImgViewH);
    [_xyAvatar sd_setImageWithURL:[NSURL URLWithString:self.xyBusinessCellItem.image_url] placeholderImage:nil];
    
    
    CGFloat userNameLabelX = xyPadding + CGRectGetMaxX(self.xyAvatar.frame);
    CGFloat userNameLabelY = headImgViewY;
    CGFloat userNameLabelH = headImgViewH/2;
    CGSize  userNameLabelSize =[XYCommon xy_getSizeWithStr:_xyBusinessCellItem.create_name font:xyUserNameTextFont maxSize:CGSizeMake(xyUserNameLableW, userNameLabelH)];
    _userNameLabel.text = _xyBusinessCellItem.create_name;
    
    CGFloat userNameLabelW = userNameLabelSize.width;
    _userNameLabel.frame = CGRectMake(userNameLabelX, userNameLabelY, userNameLabelW, userNameLabelH);
    
    CGFloat publishTimeLabelW = xyPublisTimeLabelW;
    CGFloat publishTimeLabelH = userNameLabelH;
    CGFloat publishTimeLabelX = WDScreenW - publishTimeLabelW - xyPadding;
    CGFloat publishTimeLabelY = self.userNameLabel.frame.origin.y;
    
    self.publishTimeLabel.frame = CGRectMake(publishTimeLabelX, publishTimeLabelY, publishTimeLabelW, publishTimeLabelH);
    self.publishTimeLabel.text = self.xyDetailItem.create_time;
}

- (void)xySetBlowSubviewsFrameWithY:(CGFloat)xyContentMaxY withOriginX:(CGFloat)xyOriginX{
    CGFloat xyContentX = xyOriginX + xyPadHalf;
    CGFloat xyContentY = xyContentMaxY + xyPadding *2;
    CGFloat xyContentW = WDScreenW - xyContentX *2;
    CGFloat xyContentH = 0;
    CGSize xyContentSize = [XYCommon xy_getSizeWithStr:_xyDetailItem.content font:xyCallDetailContentFont maxSize:CGSizeMake(xyContentW, MAXFLOAT)];
    xyContentH = xyContentSize.height;
    _xyContentLabel.frame = CGRectMake(xyContentX, xyContentY, xyContentW, xyContentH);
    
    
    CGFloat xyMsgImgViewW = xy(18);
    CGFloat xyMsgImgViewH = xy(17);
    CGFloat xyMsgImgViewX = WDScreenW - xyMsgImgViewW - xyPadding;
    CGFloat xyMsgImgViewY = CGRectGetMaxY(_xyContentLabel.frame)+xyPadding *2;
    _xyMsgImgView.frame = CGRectMake(xyMsgImgViewX, xyMsgImgViewY, xyMsgImgViewW, xyMsgImgViewH);
    _xyH = CGRectGetMaxY(_xyMsgImgView.frame) + xyPadding;
    
    CGFloat xyAlertLabelX = 0;
    CGFloat xyAlertLabelY = CGRectGetMaxY(_xyMsgImgView.frame)+xyPadding *2;
    CGFloat xyAlertLabelW = WDScreenW;
    CGFloat xyAlertLabelH = xy(20);
    
    if(_xyDetailItem.chat_data.count >0){
        
    }else{
        _xyAlertLabel.frame = CGRectMake(xyAlertLabelX, xyAlertLabelY, xyAlertLabelW, xyAlertLabelH);
        _xyH = CGRectGetMaxY(_xyAlertLabel.frame) + xyPadding*2;
        
    }
}

- (void)setXyDetailItem:(XYCallDetailItem *)xyDetailItem{
    _xyDetailItem = xyDetailItem;
    [self xySetSubviewsFrame];
    _xyContentLabel.text = xyDetailItem.content;
    
}



@end













